package org.xiyu.yee.beacon_anti_phantom;

import net.minecraft.server.level.ServerLevel;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.tick.LevelTickEvent;
import net.neoforged.neoforge.event.server.ServerStartedEvent;
import org.xiyu.yee.beacon_anti_phantom.event.ServerEventHandler;

@Mod(Constants.MOD_ID)
public class Beacon_anti_phantom {

    public Beacon_anti_phantom(IEventBus eventBus) {
        // This method is invoked by the NeoForge mod loader when it is ready
        // to load your mod. You can access NeoForge and Common code in this
        // project.

        // Use NeoForge to bootstrap the Common mod.
        Constants.LOG.info("Hello NeoForge world!");
        CommonClass.init();
        
        // 注册服务器事件
        NeoForge.EVENT_BUS.register(this);
    }
    
    @SubscribeEvent
    public void onServerTick(LevelTickEvent.Post event) {
        if (!event.getLevel().isClientSide()) {
            ServerEventHandler.getInstance().onServerTick((ServerLevel) event.getLevel());
        }
    }
    
    @SubscribeEvent
    public void onServerStarted(ServerStartedEvent event) {
        ServerEventHandler.getInstance().onServerStarted();
        Constants.LOG.info("Beacon Anti-Phantom mod is now active on server!");
    }
}
